﻿using DAL.Entities;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL.YQZS
{
    public class YqdataDAL
    {
        private readonly DataContext _dataContext;
        public YqdataDAL(DataContext dataContext)
        {
            _dataContext = dataContext;
        }


        //总是得到最新数据

        public Yqdata GetYqdata(int type, DateTime time)
        {
            var stime = time.AddHours(-3);
            var data = _dataContext.Yqdatas.Where(x => x.Type == type && x.CreateTime > stime && x.CreateTime <= time).OrderByDescending(x => x.CreateTime).FirstOrDefault();
            return data;
        }


        public void CreateAsync(Yqdata entity)
        {
            _dataContext.Entry(entity).State = EntityState.Added;
        }

        public void SaveChanges()
        {
            _dataContext.SaveChanges();
        }
    }
}
